//
//  HQShopFiltrateConditionView.m
//  MobileiOS
//
//  Created by 郝庆松 on 2018/7/9.
//  Copyright © 2018年 PCITC. All rights reserved.
//

#import "HQShopFiltrateConditionView.h"

@implementation HQShopFiltrateConditionView

-(void)selectDict:(NSDictionary *)dict{
    _dict1 = dict;    
}

+ (instancetype)loadShopFiltrateView{
    return [[[NSBundle mainBundle] loadNibNamed:@"HQShopFiltrateConditionView" owner:nil options:nil] lastObject];
}

- (void)awakeFromNib{
    [super awakeFromNib];
    
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    
    _layout.sectionInset = UIEdgeInsetsMake(0, 0, 1, 0);
    _layout.minimumInteritemSpacing = 1;
    _layout.minimumLineSpacing = 1;
    
    [_collectionView registerNib:[UINib nibWithNibName:@"HQFiltrateViewCell" bundle:nil] forCellWithReuseIdentifier:@"HQFiltrateViewCell"];
}

-(void)setDataSource:(NSMutableArray *)dataSource{
    _dataSource = dataSource;
    [self.collectionView reloadData];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _dataSource.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HQFiltrateViewCell *cell = [HQFiltrateViewCell cellWithCollectionView:collectionView withIndexPath:indexPath];
    NSDictionary *dict = _dataSource[indexPath.row];
    if([_dict1 isEqual:dict]){
        cell.backView.backgroundColor = [self colorHexValue:0x65AEE8];
    }else{
        cell.backView.backgroundColor = [self colorHexValue:0xf1f2f3];
    }
    if([self.type isEqualToString:@"stylelists"]){
        cell.itemName.text = _dataSource[indexPath.row][@"tse_name"];
    }else if([self.type isEqualToString:@"pricelists"]){
        cell.itemName.text = _dataSource[indexPath.row][@"tpe_name"];
    }else if([self.type isEqualToString:@"fctlists"]){
        cell.itemName.text = _dataSource[indexPath.row][@"shop_name"];
    }else if([self.type isEqualToString:@"online"]){
        cell.itemName.text = _dataSource[indexPath.row][@"name"];
    }else if([self.type isEqualToString:@"sortprice"]){
        cell.itemName.text = _dataSource[indexPath.row][@"name"];
    }
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    _dict1 = _dataSource[indexPath.row];
    [_collectionView reloadData];
}

- (IBAction)resetItem:(id)sender {
    _dict1 = nil;
    [_collectionView reloadData];
}

- (IBAction)contentItem:(id)sender {
    [self.delegate filterDict:_dict1 withType:self.type];
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake((SCREEN_WIDTH-2)/2, 40);
}

@end
